"""WordCount pyquick exercise.

The main() below is already defined and complete. It calls Count()
and TopCount() functions which you write.

1. For the --count flag, implement a Count(filename) function that counts
how often each word appears in the text and prints:
word1 count1
word2 count2
...

Print the above list in order sorted by word (python will sort punctuation to
come before letters -- that's fine). Store all the words as lowercase,
so 'The' and 'the' count as the same word.

2. For the --topcount flag, implement a TopCount(filename) which is similar
to Count() but which prints just the top 20 most common words sorted
so the most common word is first, then the next most common, and so on.

Use str.split() (no arguments) to split on all whitespace.

Workflow: don't build the whole program at once. Get it to an intermediate
milestone and print your data structure and sys.exit(0).
When that's working, try for the next milestone.

Optional: define a helper function to avoid code duplication inside
Count() and TopCount().

"""
import sys

# +++your code here+++
def GetFileDict(filename):
  dict = {}
  return dict

def First(tuple):
  return tuple[0]

def Last(tuple):
  return tuple[-1]

# Define Count(filename) and TopCount(filename) functions
def Count(filename):
  pass

def TopCount(filename):
  pass

# This main() command line argument parsing is provided and
# calls the Count() and TopCount() functions which you must define.
def main():
  if len(sys.argv) != 3:
    print 'usage: wordcount.py {--count | --topcount} file'
    sys.exit(1)

  option = sys.argv[1]
  filename = sys.argv[2]
  if option == '--count':
    Count(filename)
  elif option == '--topcount':
    TopCount(filename)
  else:
    print 'unknown option: ' + option
    sys.exit(1)

if __name__ == '__main__':
  main()
